package com.example.allshengmedical.experimentnew.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import android.R.array;
import android.R.integer;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.Selection;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.allsheng.widget.AllShengDialog;
import com.allsheng.widget.AllShengDialog.ClickListenerInterface;
import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseActivity;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.experimentnew.presenter.MethodsPresenter;
import com.example.allshengmedical.experimentnew.view.IMethodsView;
import com.example.allshengmedical.experimentrun.activity.RunPreviewActivity;
import com.example.allshengmedical.experimentrun.activity.RunPreviewActivity.RecyclerViewAdapter;
import com.example.allshengmedical.mainmenu.activity.MainMenuActivity;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.FileManagerUtil;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.MyHorizontalScrollView;
import com.example.allshengmedical.util.ScrollViewListener;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.example.allshengmedical.util.SimpleLineChart;

//编辑方法页面的内容
public class EditMethodsActivity extends BaseActivity implements IMethodsView,
		OnClickListener, ScrollViewListener {

	private RecyclerView steptRv;
	private RecyclerViewAdapter recyclerViewAdapter;
	public ArrayList<MethodBean> activityMethodBeans;
	private ImageView addIv;

	private MethodsPresenter methodsPresenter;

	private boolean menuboo;
	private PopupWindow menuPopupWindow, showMethodsPopupWindow;

	private SimpleLineChart mSimpleLineChart;
	private int pointnumber;
	private String[] xItem, yItem;

	private List<String> data_list = new ArrayList<String>();
	private ArrayAdapter<String> arr_adapter;

	// 保证线不交叉
	private HashSet<ArrayList<Integer>> range = new HashSet<ArrayList<Integer>>();
	// 保证每个终点不超过三个
	private HashMap<Integer, Integer> point3 = new HashMap<Integer, Integer>();

	// 下面的图表
	public HashMap<Integer, Integer> pointMap = new HashMap();
	public List<HashMap<String, Object>> pointMaps = new ArrayList<HashMap<String, Object>>();

	// 下面的横划
	MyHorizontalScrollView downScrollView, upScrollView;

	//
	private LinearLayout reLine;

	private FileManagerUtil fileManagerUtil;

	private TextView totalTv;

	public static EditMethodsActivity context;

	// 右边侧滑菜单
	String hotLidTemperature = "";
	String sampleVolumeString = "";
	String readDataString = "";
	Boolean holdingCheckBox = false;
	String fourduString = "4";

	// 摄像机是否设置如果未设置不能进行跳转
	Boolean cameraBoolean = false;

	// 数据
	String folderName;
	String fileName;
	private String appFilePath = Environment.getExternalStorageDirectory()
			+ "/" + "AllShengMedical";
	StringBuffer contextString = new StringBuffer();
	private String editTextString;
	ImageView hotValueIv;

	public static EditMethodsActivity getInstence() {
		return context;
	}

	@Override
	protected int setcontent() {
		return R.layout.activity_new_methods1;
	}

	@Override
	protected void initView() {

		context = this;
		fileManagerUtil = new FileManagerUtil();

		downScrollView = BindView(R.id.downScrollView);
		downScrollView.setScrollViewListener(this);
		upScrollView = BindView(R.id.upScrollView);
		upScrollView.setScrollViewListener(this);

		methodsPresenter = new MethodsPresenter(this);
		methodsPresenter.initAppHead();
		methodsPresenter.initBottomView();

		initRecyclerView();

		// reLine.post(new Runnable() {
		//
		// @Override
		// public void run() {
		// // Log.d(TAG, "Runable invoke");
		// // 构造一个 "矩型" 对象
		// Rect delegateArea = new Rect();
		// RecyclerView delegate = steptRv;
		// // Hit rectangle in parent's coordinates
		// delegate.getHitRect(delegateArea);
		// // Log.d(TAG, "——————————原始触摸矩阵区域————————");
		// // Log.d(TAG,
		// //
		// "width: "+delegateArea.width()+" | height: "+delegateArea.height());
		// // Log.d(TAG, "left: "+delegateArea.left +
		// // " | Top: "+delegateArea.top +
		// //
		// " | right: "+delegateArea.right+" | bottom: "+delegateArea.bottom);
		//
		// // 扩大触摸区域矩阵值
		// delegateArea.left -= 500;
		// delegateArea.top -= 500;
		// delegateArea.right += 500;
		// delegateArea.bottom += 15000;
		//
		// // Log.d(TAG, "——————————扩大触摸区域后  矩阵区域————————");
		// // Log.d(TAG,
		// //
		// "width: "+delegateArea.width()+" | height: "+delegateArea.height());
		// // Log.d(TAG, "left: "+delegateArea.left +
		// // " | Top: "+delegateArea.top +
		// //
		// " | right: "+delegateArea.right+" | bottom: "+delegateArea.bottom);
		// /**
		// * 构造扩大后的触摸区域对象 第一个构造参数表示 矩形面积 第二个构造参数表示 被扩大的触摸视图对象
		// * <也是本demo最核心用到的类之一>
		// */
		// TouchDelegate expandedArea = new TouchDelegate(delegateArea,
		// delegate);
		//
		// if (View.class.isInstance(delegate.getParent())) {
		// // 设置视图扩大后的触摸区域
		// ((View) delegate.getParent())
		// .setTouchDelegate(expandedArea);
		// }
		//
		// }
		// });
		initSimpleLineChart();
		totalTv.setText("总计" + activityMethodBeans.size() + "步");

	}

	@Override
	protected void initData() {

		point3.put(1, 0);
		point3.put(2, 0);
		point3.put(3, 0);
		point3.put(4, 0);
		point3.put(5, 0);
		point3.put(6, 0);
		point3.put(7, 0);
		point3.put(8, 0);
		point3.put(9, 0);
		point3.put(10, 0);
		point3.put(11, 0);
		point3.put(12, 0);
		point3.put(13, 0);
		point3.put(14, 0);
		point3.put(15, 0);
		point3.put(16, 0);
		point3.put(17, 0);
		point3.put(18, 0);
		point3.put(19, 0);
		point3.put(20, 0);

		getInfo();
		initSimpleLineChartView();

	}

	private void initSimpleLineChartView() {
		mSimpleLineChart = (SimpleLineChart) findViewById(R.id.simpleLineChart);
		activityMethodBeans = new ArrayList<MethodBean>();

		int index = editTextString.indexOf("Methods");
		// 上面解析
		while (!(editTextString.indexOf("steptType:", index) <= 0)) {

			// steptType:
			String steptType;
			steptType = editTextString.substring(
					editTextString.indexOf("steptType:", index) + 10,

					editTextString.indexOf(",temperature:", index));

			// LogUtil.e(steptType);

			// temperature
			String temperature;
			temperature = editTextString.substring(
					editTextString.indexOf(",temperature:", index) + 13,

					editTextString.indexOf(",time:", index));

			// LogUtil.e(temperature);
			// time
			String time;
			time = editTextString.substring(
					editTextString.indexOf(",time:", index) + 6,

					editTextString.indexOf(",goTo:", index));
			// LogUtil.e(time);

			// goTo
			String goTo;
			goTo = editTextString.substring(
					editTextString.indexOf(",goTo:", index) + 6,

					editTextString.indexOf(",Repititions:", index));
			// LogUtil.e(goTo);
			// Repititions
			String repititions;
			repititions = editTextString.substring(
					editTextString.indexOf(",Repititions:", index) + 13,

					editTextString.indexOf(",deltaT:", index));
			// LogUtil.e(repititions);
			// deltaT
			String deltaT;
			deltaT = editTextString.substring(
					editTextString.indexOf(",deltaT:", index) + 8,

					editTextString.indexOf(",rightSelect:", index));
			// LogUtil.e(deltaT);

			int nextIndex = editTextString.indexOf("steptType:", index) + 10;

			// rightSelect
			Boolean rightSelect;

			if (editTextString.indexOf(",steptType:", nextIndex) < 0) {
				rightSelect = Boolean.parseBoolean(editTextString.substring(
						editTextString.indexOf(",rightSelect:", index) + 13,
						editTextString.indexOf(",,pointMap", index)).trim());
				if ("null".equals(rightSelect)) {
					rightSelect = false;
				}

			} else {
				rightSelect = Boolean.parseBoolean(editTextString.substring(
						editTextString.indexOf(",rightSelect:", index) + 13,

						editTextString.indexOf(",steptType:", nextIndex))
						.trim());
				if ("null".equals(rightSelect)) {
					rightSelect = false;
				}
			}
			// LogUtil.e(rightSelect);
			index = editTextString.indexOf(",rightSelect:", index) + 13;

			activityMethodBeans.add(new MethodBean(steptType.trim(),
					temperature.trim(), time.trim(), goTo.trim(), repititions
							.trim(), deltaT.trim(), rightSelect));
		}
		// 上面配置完成
		steptRv = BindView(R.id.steptRv);
		LayoutManager layoutManager = new GridLayoutManager(this, 1);
		((GridLayoutManager) layoutManager)
				.setOrientation(OrientationHelper.HORIZONTAL);
		steptRv.setLayoutManager(layoutManager);
		recyclerViewAdapter = new RecyclerViewAdapter(activityMethodBeans);
		steptRv.setAdapter(recyclerViewAdapter);

		// 下面解析
		int num = 1;
		pointMap = new HashMap<Integer, Integer>();
		if (editTextString.indexOf(",,Channel1") > 0) {
			// 已经有实验数据的实验
			while (!(editTextString.indexOf("pointMap", index) <= 0)) {

				int pointMapValue = 0;
				// int nextIndex = contextString.indexOf("pointMap", index);

				if (editTextString.indexOf("pointMap" + num) < 0) {
					// pointMap = Integer
					// .parseInt(contextString.substring(contextString
					// .indexOf("pointMap"+num, index) + 10));

				} else {
					if (editTextString.indexOf("pointMap" + (num + 1)) < 0) {
						// pointMap = Integer.parseInt(contextString
						// .substring(
						// contextString.indexOf("pointMap:" + num,
						// index) + 9).trim());
						if (num < 10) {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 11,
											editTextString
													.indexOf(",,Channel1"))
											.trim());
						} else {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 11,
											editTextString
													.indexOf(",,Channel1"))
											.trim());
						}

						LogUtil.e(pointMapValue);
						pointMap.put(num - 1, pointMapValue);
						break;

					} else {

						if (num < 10) {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 10,
											editTextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						} else {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 11,
											editTextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						}

					}

				}
				pointMap.put(num - 1, pointMapValue);
				num++;
				index = editTextString.indexOf("pointMap", index);
				LogUtil.e(pointMapValue);

			}
		} else {
			while (!(editTextString.indexOf("pointMap", index) <= 0)) {

				int pointMapValue = 0;
				// int nextIndex = contextString.indexOf("pointMap", index);

				if (editTextString.indexOf("pointMap" + num) < 0) {
					// pointMap = Integer
					// .parseInt(contextString.substring(contextString
					// .indexOf("pointMap"+num, index) + 10));

				} else {
					if (editTextString.indexOf("pointMap" + (num + 1)) < 0) {
						// pointMap = Integer.parseInt(contextString
						// .substring(
						// contextString.indexOf("pointMap:" + num,
						// index) + 9).trim());
						if (num < 10) {
							// pointMapValue = Integer.parseInt(contextString
							// .substring(
							// contextString.indexOf("pointMap"
							// + num) + 10).trim());

							String xString = editTextString
									.substring(editTextString
											.indexOf("pointMap" + num) + 10);
							if (!(",,".equals(xString))) {
								pointMapValue = 10 - Integer.parseInt(xString
										.substring(0, xString.length() - 1)
										.trim());
							}

							// (contextString.substring(contextString
							// .indexOf("pointMap" + num) + 10))
							// .substring((contextString.substring(
							// contextString.indexOf("pointMap"
							// + num) + 10).length() - 1));

						} else {
							pointMapValue = 10 - Integer
									.parseInt(editTextString
											.substring(
													editTextString
															.indexOf("pointMap"
																	+ num) + 11)
											.trim()
											.substring(
													0,
													editTextString
															.substring(
																	editTextString
																			.indexOf("pointMap"
																					+ num) + 11)
															.trim().length() - 1));
						}

						LogUtil.e(pointMapValue);
						pointMap.put(num - 1, pointMapValue);
						break;

					} else {

						if (num < 10) {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 10,
											editTextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						} else {
							pointMapValue = 10 - Integer
									.parseInt(editTextString.substring(
											editTextString.indexOf("pointMap"
													+ num) + 11,
											editTextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						}

					}

				}
				pointMap.put(num - 1, pointMapValue);
				num++;
				index = editTextString.indexOf("pointMap", index);
				LogUtil.e(pointMapValue);

			}
		}

		LogUtil.e(pointMap);

		// pointmaps
		pointMaps = new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < 40; i++) {
			HashMap<String, Object> itemHashMap = new HashMap<String, Object>();
			// x
			itemHashMap.put("x", i);
			// y
			itemHashMap.put("y", "");
			// 温度
			itemHashMap.put("temperature", "");
			// 时间
			itemHashMap.put("time", "");
			// DeltaT
			itemHashMap.put("deltaT", "");
			// gotTo
			itemHashMap.put("goTo", "");
			// Repititions
			itemHashMap.put("repititions", "");
			pointMaps.add(itemHashMap);

		}
		// 初始化
		mSimpleLineChart = BindView(R.id.simpleLineChart);

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
		String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
		pointnumber = activityMethodBeans.size();
		mSimpleLineChart.setYItem(yItem);
		UpdateView();

		// hotLidTemperature
		// sampleVolumeString
		// readDataString

		// if (goToTv.getText().toString() != null
		// && !"".equals(goToTv.getText().toString())) {
		// ArrayList<Integer> linShilist = new ArrayList<Integer>();
		// linShilist.add(Integer
		// .parseInt(goToTv.getText().toString()));
		// linShilist.add(activityMethodBeans.size() + 1);
		//

		//
		// range.add(linShilist);
		// }
		//
		// range

		ArrayList<Integer> linShilist;
		for (int i = 0; i < activityMethodBeans.size(); i++) {
			if (!TextUtils.isEmpty(activityMethodBeans.get(i).getGoTo())) {
				linShilist = new ArrayList<Integer>();
				linShilist.add(Integer.parseInt(activityMethodBeans.get(i)
						.getGoTo().trim()));
				linShilist.add(i + 1);
				range.add(linShilist);
			}
		}
		holdingCheckBox =Boolean.parseBoolean(contextString.substring(
				contextString.indexOf("holdingCheckBox:") + 16,
				contextString.indexOf(",fourduString:")));
		fourduString=contextString.substring(
				contextString.indexOf("fourduString:") + 13,
				contextString.indexOf(",hotLidTemperature:"));
		hotLidTemperature = contextString.substring(
				contextString.indexOf("hotLidTemperature:") + 18,
				contextString.indexOf(",sampleVolumeString:"));
		sampleVolumeString = contextString.substring(
				contextString.indexOf("sampleVolumeString:") + 19,
				contextString.indexOf(",readDataString:"));
		readDataString = contextString.substring(
				contextString.indexOf("readDataString:") + 15,
				contextString.indexOf(",,",
						contextString.indexOf("readDataString:")));

	}

	private void getInfo() {
		folderName = SharedPreferencesUtils.get(EditMethodsActivity.this,
				BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(EditMethodsActivity.this,
				BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		BufferedReader reader = null;
		try {
			System.out.println("以行为单位读取文件内容，一次读一整行:");
			reader = new BufferedReader(new FileReader(file));
			String tempString = "";
			int line = 1;
			// 一次读入一行，直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				// System.out.println("line " + line + ": " + tempString);
				// Log.e("--", tempString);
				contextString.append(tempString);
				contextString.append(",");
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
					LogUtil.e("!!", contextString + "");

				} catch (IOException e1) {
				}
			}
		}
		editTextString = contextString.substring(
				contextString.indexOf(",,Methods,,"), contextString.length());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.addIv:

			selectTypePopupWindow(v);
			break;
		case R.id.hotValueIv:

			showMethodsPopupWindow(v);

			// showMethodsPopupWindow.dismiss();

			break;
		default:
			break;
		}

	}

	@Override
	public void initAppHead() {
		setActionBar();
		setSystemTime();

	}

	@Override
	public void initBottomView() {
		setBottomView();

	}

	@Override
	public void AddAStep(View v) {
		chooseMethodPopupWindow(v);
	}

	@Override
	public void solubilityCurveEdit() {
		// TODO Auto-generated method stub

	}

	@Override
	public void steptEdit() {
		// TODO Auto-generated method stub

	}

	// 设置actionBar
	public void setActionBar() {
		Button leftfirstBtn, leftsecondBtn, leftThirdBtn, leftForthBtn, rightfirstBtn, rightsecondBtn, rightthirdBtn;
		final Button rightforthBtn;
		TextView title;

		leftfirstBtn = BindView(R.id.leftfirst_btn);
		leftsecondBtn = BindView(R.id.leftsecond_btn);
		rightfirstBtn = BindView(R.id.rightfirst_btn);
		rightsecondBtn = BindView(R.id.rightsecond_btn);
		rightthirdBtn = BindView(R.id.rightthird_btn);
		rightforthBtn = BindView(R.id.rightforth_btn);
		leftThirdBtn = BindView(R.id.leftThird_btn);
		leftForthBtn = BindView(R.id.leftForth_btn);

		title = BindView(R.id.title);

		leftfirstBtn.setVisibility(View.GONE);
		leftfirstBtn.setText(R.string.item_actionbar_menu);
		leftsecondBtn.setVisibility(View.VISIBLE);
		leftsecondBtn.setText(R.string.item_actionbar_home);
		rightfirstBtn.setVisibility(View.GONE);
		rightfirstBtn.setText(R.string.actionBar_new);
		rightsecondBtn.setVisibility(View.GONE);
		rightsecondBtn.setText(R.string.actionBar_saveAs);
		rightthirdBtn.setVisibility(View.GONE);
		rightthirdBtn.setText(R.string.actionBar_save);
		leftThirdBtn.setVisibility(View.VISIBLE);
		leftThirdBtn.setText("載入模板");
		leftForthBtn.setVisibility(View.VISIBLE);
		leftForthBtn.setText("保存模板");

		rightforthBtn.setVisibility(View.VISIBLE);

		title.setText("Methods");

		leftfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!menuboo) {
					showMenuPopupWindow(v);
					menuboo = !menuboo;
				} else {
					menuPopupWindow.dismiss();
					menuboo = !menuboo;
				}

			}

		});

		leftsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				BaseApplication.getInstance().finishAll();
				Intent intent = new Intent(EditMethodsActivity.this,
						MainMenuActivity.class);
				startActivity(intent);
			}
		});

		rightfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("New");
				Intent intent = new Intent(EditMethodsActivity.this,
						FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("Save As");
				Intent intent = new Intent(EditMethodsActivity.this,
						FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightthirdBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				savePopupWindow(v);

			}

		});
		rightforthBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				// if (!rightforthBtn.isSelected()) {
				// rightforthBtn.setSelected(!rightforthBtn.isSelected());
				// showMethodsPopupWindow(v);
				// } else {
				// rightforthBtn.setSelected(!rightforthBtn.isSelected());
				// showMethodsPopupWindow.dismiss();
				// ByAlert.alert("dissmisspopwindow");
				// }

			}
		});

		leftThirdBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ByAlert.alert("loadMethods");

			}
		});
		leftForthBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ByAlert.alert("saveMethods");

			}
		});

	}

	// 获取当前时间的方法
	public void setSystemTime() {

		TextView date, fileName;
		date = BindView(R.id.date);
		fileName = BindView(R.id.file_name);

		// 获取系统时间
		SimpleDateFormat sdfDate = new SimpleDateFormat("MM dd,yyyy");
		date.setText(sdfDate.format(new Date()));

		// 文件路径置空
		fileName.setText("");

	}

	// 设置bottom布局
	public void setBottomView() {
		Button bottomLeftFistBtn, bottomCenterBtn, bottomRightBtn;

		bottomLeftFistBtn = BindView(R.id.bottomLeftFistBtn);
		bottomCenterBtn = BindView(R.id.bottomCenterBtn);
		bottomRightBtn = BindView(R.id.bottomRightBtn);

		bottomLeftFistBtn.setVisibility(View.VISIBLE);
		// bottomCenterBtn.setVisibility(View.VISIBLE);
		bottomRightBtn.setVisibility(View.VISIBLE);

		bottomLeftFistBtn.setText(R.string.bottomView_back);
		// TODO 这个button的文字不确定暂时用A代替
		bottomCenterBtn.setText("A"); // 不确定！！！！！！！
		bottomRightBtn.setText(R.string.bottomView_next);

		bottomLeftFistBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// ByAlert.alert("back");
				finish();

			}
		});

		bottomCenterBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("A");

			}
		});
		bottomRightBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (cameraBoolean) {

				} else {
					ByAlert.alert(getString(R.string.editmethod_camera));
					return;
				}

				// 编辑的思路：首先要全部读取（不加逗号），遇到关键信息删除。然后加上新内容。最后重写文件
				String path = appFilePath + "/" + folderName;
				File file = new File(path + "/" + fileName);
				BufferedReader reader = null;
				// contextString = new StringBuffer();
				// contextString.append("ExperimentName:"
				// + experimentNameET.getText());
				// contextString.append("\r\n" + "ExperimentID:"
				// + experimentIdEt.getText());
				// contextString.append("\r\n" + "Experimenter:"
				// + experimenterEt.getText());
				// contextString.append("\r\n"
				// + "ExperimentType:"
				// + spinnerExperTypeData_list.get(spinnerExperType
				// .getSelectedItemPosition()));
				// contextString.append("\r\n"
				// + "SampleType:"
				// + spinnerSampleTypeData_list.get(spinnerSampleType
				// .getSelectedItemPosition()));
				// contextString.append("\r\n"
				// + "Reagent:"
				// + spinnerReagentData_list.get(spinnerReagent
				// .getSelectedItemPosition()));
				// contextString.append("\r\n");

				try {
					System.out.println("以行为单位读取文件内容，一次读一整行:");
					reader = new BufferedReader(new FileReader(file));

					String tempString = "";
					contextString = new StringBuffer();
					int line = 1;
					// 一次读入一行，直到读入null为文件结束
					while ((tempString = reader.readLine()) != null) {
						// 显示行号
						// System.out.println("line " + line + ": " +
						// tempString);
						// Log.e("--", tempString);
						if (tempString.equals("cameraSet")) {
							break;
						}

						contextString.append(tempString);
						contextString.append("\r\n");
						line++;
					}
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				} finally {
					if (reader != null) {
						try {
							reader.close();
							LogUtil.e("!!", contextString + "");

						} catch (IOException e1) {
						}
					}
				}

				// StringBuffer content = new StringBuffer();

				contextString.append("cameraSet" + "\r\n");
				contextString.append("\r\n" + "holdingCheckBox" + ": "
						+ holdingCheckBox);
				contextString.append("\r\n" + "fourduString" + ": "
						+ fourduString);
				contextString.append("\r\n" + "hotLidTemperature" + ": "
						+ hotLidTemperature);
				contextString.append("\r\n" + "sampleVolumeString" + ": "
						+ sampleVolumeString);
				contextString.append("\r\n" + "readDataString" + ": "
						+ readDataString);

				contextString.append("\r\n" + "\r\n" + "Methods" + "\r\n");

				for (MethodBean bean : activityMethodBeans) {
					contextString.append("\r\n" + "steptType: "
							+ bean.getSteptType());
					contextString.append("\r\n" + "temperature: "
							+ bean.getTemperature());
					contextString.append("\r\n" + "time: " + bean.getTime());
					contextString.append("\r\n" + "goTo: " + bean.getGoTo());
					contextString.append("\r\n" + "Repititions: "
							+ bean.getRepititions());
					contextString.append("\r\n" + "deltaT: " + bean.getDeltaT());
					contextString.append("\r\n" + "rightSelect: "
							+ bean.getRightSelect());

				}

				contextString.append("\r\n" + "\r\n" + "pointMap" + "\r\n");

				for (int i = 0; i < pointMap.size(); i++) {
					// pointMap.get(i)
					int index = i + 1;
					int result = 10 - Integer.parseInt(pointMap.get(i) + "");
					contextString.append("\r\n" + "pointMap" + index + ": "
							+ result);

				}
				// contextString.append(content);

				fileManagerUtil.createFIle(folderName, fileName);
				fileManagerUtil.writeFile(folderName, fileName, contextString
						+ "", false);

				Intent intent = new Intent(EditMethodsActivity.this,
						RunPreviewActivity.class);
				startActivity(intent);

				// // 创建文件
				// String folderName = SharedPreferencesUtils.get(
				// EditMethodsActivity.this,
				// BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0")
				// + "";
				// String fileName = SharedPreferencesUtils.get(
				// EditMethodsActivity.this,
				// BaseApplication.FILEMANGER_PREPAREFILENAME, "0")
				// + "";
				//
				// StringBuffer content = new StringBuffer();
				//
				// content.append("\r\n" + "\r\n" + "cameraSet" + "\r\n");
				// content.append("\r\n" + "hotLidTemperature" + ": "
				// + hotLidTemperature);
				// content.append("\r\n" + "sampleVolumeString" + ": "
				// + sampleVolumeString);
				// content.append("\r\n" + "readDataString" + ": "
				// + readDataString);
				//
				// content.append("\r\n" + "\r\n" + "Methods" + "\r\n");
				//
				// for (MethodBean bean : activityMethodBeans) {
				// content.append("\r\n" + "steptType: " + bean.getSteptType());
				// content.append("\r\n" + "temperature: "
				// + bean.getTemperature());
				// content.append("\r\n" + "time: " + bean.getTime());
				// content.append("\r\n" + "goTo: " + bean.getGoTo());
				// content.append("\r\n" + "Repititions: "
				// + bean.getRepititions());
				// content.append("\r\n" + "deltaT: " + bean.getDeltaT());
				// content.append("\r\n" + "rightSelect: "
				// + bean.getRightSelect());
				//
				// }
				//
				// content.append("\r\n" + "\r\n" + "pointMap" + "\r\n");
				//
				// for (int i = 0; i < pointMap.size(); i++) {
				// // pointMap.get(i)
				// int index = i + 1;
				// int result = 10 - Integer.parseInt(pointMap.get(i) + "");
				// content.append("\r\n" + "pointMap" + index + ": " + result);
				//
				// }
				//
				// // for (int i = 0; i < pointMaps.size(); i++) {
				// // // pointMap.get(i)
				// // int index = i + 1;
				// // int result = 10 - Integer.parseInt(pointMap.get(i) + "");
				// // content.append("\r\n" + "pointMap" + index + ": " +
				// result);
				// //
				// // }
				//
				// // for (MethodBean bean : pointMap) {
				// //
				// // pointMap
				// // pointMap.get(key)
				// //
				// // }
				//
				// fileManagerUtil.createFIle(folderName, fileName);
				// fileManagerUtil.writeFile(folderName, fileName, content + "",
				// true);
				//
				// Intent intent = new Intent(EditMethodsActivity.this,
				// RunPreviewActivity.class);
				// startActivity(intent);
				// finish();
			}
		});
	}

	// menu的弹出窗口
	private void showMenuPopupWindow(View v) {

		if (null == menuPopupWindow || !menuPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(this).inflate(
					R.layout.fragment_new_basicinformation_menu, null);

			menuPopupWindow = new PopupWindow(contentView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			menuPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			menuPopupWindow.setTouchable(true);
			menuPopupWindow.setOutsideTouchable(true);
			menuPopupWindow.showAsDropDown(v, -40, -3);

			TextView basicInformationTv, layoutTv, methodTv, previewTv;
			basicInformationTv = (TextView) contentView
					.findViewById(R.id.basicInformationTv);
			layoutTv = (TextView) contentView.findViewById(R.id.layoutTv);
			methodTv = (TextView) contentView.findViewById(R.id.methodTv);
			previewTv = (TextView) contentView.findViewById(R.id.previewTv);

			basicInformationTv.setBackground(getResources().getDrawable(
					R.color.darkBlue));
			basicInformationTv.setTextColor(this.getResources().getColor(
					R.color.white));
			layoutTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面layout");

				}
			});
			methodTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面method");
				}
			});
			previewTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面preview");
				}
			});

		} else {
			menuPopupWindow.dismiss();
			menuboo = !menuboo;
		}

	}

	private void savePopupWindow(View v) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_baseinformation_save, null);

		Button confirmBtn, cancelBtn;

		confirmBtn = (Button) conteView.findViewById(R.id.confirm_btn);
		cancelBtn = (Button) conteView.findViewById(R.id.cancel_btn);

		final PopupWindow popupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		popupWindow.setTouchable(true);

		popupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setTouchable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);

		confirmBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// if (!whetherNull()) {
				// ByAlert.alert("保存失败");
				// popupWindow.dismiss();
				// return;
				// }
				// 创建文件

				popupWindow.dismiss();
			}

		});
		cancelBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				popupWindow.dismiss();
			}
		});

	}

	private void chooseMethodPopupWindow(View v) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_methods_step, null);

		TextView stepTv, solubilityCurveTv;
		stepTv = (TextView) conteView.findViewById(R.id.stepTv);
		solubilityCurveTv = (TextView) conteView
				.findViewById(R.id.solubilityCurveTv);

		final PopupWindow chooseMethodPopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		stepTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				chooseMethodPopupWindow.dismiss();
			}
		});

		solubilityCurveTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				chooseMethodPopupWindow.dismiss();
			}
		});

		chooseMethodPopupWindow.setTouchable(true);

		chooseMethodPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		chooseMethodPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		chooseMethodPopupWindow.setTouchable(true);
		chooseMethodPopupWindow.setOutsideTouchable(true);
		chooseMethodPopupWindow.showAtLocation(v, Gravity.CENTER, 0, -15);
	}

	private void initRecyclerView() {
		steptRv = BindView(R.id.steptRv);
		activityMethodBeans = new ArrayList<MethodBean>();

		// // 数据
		//
		// if
		// ("SYBR".equals(SharedPreferencesUtils.get(EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		// activityMethodBeans.add(new MethodBean("step", "95", "00:20:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("step", "95", "00:01:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("step", "60", "00:20:00",
		// "2", "40", ""));
		// activityMethodBeans.add(new MethodBean("step", "95", "00:15:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("step", "60", "01:00:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("solubilityCurve", "95",
		// "00:15:00", "", "", "0.3"));
		//
		// } else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))
		// | "taqman".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		// activityMethodBeans.add(new MethodBean("step", "95", "00:20:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("step", "95", "00:01:00",
		// "", "", ""));
		// activityMethodBeans.add(new MethodBean("step", "60", "00:20:00",
		// "2", "40", ""));
		//
		// } else if ("其他".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))
		// | "Other".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		// // activityMethodBeans.add(new MethodBean("step", "50", "10:11:12",
		// // "", "", ""));
		// // activityMethodBeans.add(new MethodBean("solubilityCurve", "50",
		// // "10:11:12", "", "", "70"));
		//
		// }

		LayoutManager layoutManager = new GridLayoutManager(this, 1);
		((GridLayoutManager) layoutManager)
				.setOrientation(OrientationHelper.HORIZONTAL);
		steptRv.setLayoutManager(layoutManager);
		recyclerViewAdapter = new RecyclerViewAdapter(activityMethodBeans);
		steptRv.setAdapter(recyclerViewAdapter);

		// 添加头布局（必须在设置完布局管理器再添加头布局和脚布局）
		// 添加脚布局
		View footView = View.inflate(this,
				R.layout.item_methods_step_create_new, null);

	}

	public class RecyclerViewAdapter extends
			RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

		ArrayList<MethodBean> methodBeans = new ArrayList<MethodBean>();

		public RecyclerViewAdapter(ArrayList<MethodBean> methodBeans) {
			super();
			this.methodBeans = methodBeans;
		}

		class MyViewHolder extends ViewHolder {

			TextView titleTv;
			LinearLayout orline, line;
			ImageView exitBtn, cameraIv;

			public MyViewHolder(View view) {
				super(view);
				// temperatureTv = (TextView) view
				// .findViewById(R.id.temperatureTv);
				// timeTv = (TextView) view.findViewById(R.id.timeTv);
				// deltaTTv = (TextView) view.findViewById(R.id.deltaTTv);
				line = (LinearLayout) view.findViewById(R.id.line);
				titleTv = (TextView) view.findViewById(R.id.titleTv);
				orline = (LinearLayout) view.findViewById(R.id.orline);
				exitBtn = (ImageView) view.findViewById(R.id.exitBtn);
				cameraIv = (ImageView) view.findViewById(R.id.cameraIv);
			}
		}

		@Override
		public int getItemCount() {
			return methodBeans.size() >= 0 ? methodBeans.size() : 0;
		}

		@Override
		public int getItemViewType(int position) {

			if (position == methodBeans.size()) {
				return 0;
			}

			if ("step".equals(methodBeans.get(position).getSteptType())) {
				return 1;
			} else if ("solubilityCurve".equals(methodBeans.get(position)
					.getSteptType())) {
				return 2;
			}

			return 0;

		}

		@Override
		public void onBindViewHolder(final MyViewHolder holder,
				final int position) {
			final int index = position + 1;
			if (getItemViewType(position) == 1) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());

				holder.titleTv.setText("Step" + index);

				if (activityMethodBeans.get(position).getRightSelect()) {
					holder.cameraIv.setVisibility(View.VISIBLE);
					cameraBoolean = true;
				} else {
					holder.cameraIv.setVisibility(View.GONE);
				}

				holder.orline.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						holder.orline.setBackground(getResources().getDrawable(
								R.drawable.step_title_se));
						holder.titleTv.setTextColor(getResources().getColor(
								R.color.white));
						upDate1PopupWindow(v, position, holder.titleTv, index);

					}

				});
				holder.exitBtn.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (index != activityMethodBeans.size()) {
							if ("solubilityCurve".equals(activityMethodBeans
									.get(position + 1).getSteptType())) {
								ByAlert.alert("下一个是溶解曲线不能删除！");
								return;
							}

						}

						if (position != 0) {
							if (!TextUtils.isEmpty(activityMethodBeans.get(
									position).getGoTo())) {
								ArrayList<Integer> linshilist = new ArrayList<Integer>();
								linshilist.add(Integer
										.parseInt(activityMethodBeans.get(
												position).getGoTo()));
								linshilist.add(position);
								range.remove(linshilist);
							}

						}

						// methodBeans.remove(position);
						activityMethodBeans.remove(position);
						notifyDataSetChanged();

						HashMap<Integer, Integer> pointMap1 = new HashMap();
						pointMap1.putAll(pointMap);
						// pointMap1.remove(position * 2);
						// pointMap1.remove(position * 2 + 1);
						pointMap.clear();
						int num = 0;
						for (int i = 0; i < pointMap1.size(); i++) {
							if (!(i == position * 2 || i == position * 2 + 1)) {
								pointMap.put(num, pointMap1.get(i));
								num++;
							}

						}
						UpdateView();

						pointnumber--;

					}
				});
			} else if (getItemViewType(position) == 2) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());
				// holder.deltaTTv.setText(methodBeans.get(position).getDeltaT());
				holder.titleTv.setText("Step" + index);

				holder.orline.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						holder.orline.setBackground(getResources().getDrawable(
								R.drawable.step_title_se));
						holder.titleTv.setTextColor(getResources().getColor(
								R.color.white));
						upDate2PopupWindow(v, position, holder.titleTv, index);

					}
				});
				holder.exitBtn.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						// methodBeans.remove(position);
						activityMethodBeans.remove(position);
						notifyDataSetChanged();
						// UpdateView();

						HashMap<Integer, Integer> pointMap1 = new HashMap();
						pointMap1.putAll(pointMap);
						// pointMap1.remove(position * 2);
						// pointMap1.remove(position * 2 + 1);
						pointMap.clear();
						int num = 0;
						for (int i = 0; i < pointMap1.size(); i++) {
							if (!(i == position * 2 || i == position * 2 + 1)) {
								pointMap.put(num, pointMap1.get(i));
								num++;
							}

						}
						UpdateView();
						pointnumber--;
					}
				});
			} else {
				// holder.line.setOnClickListener(new OnClickListener() {
				//
				// @Override
				// public void onClick(View v) {
				// selectTypePopupWindow(v);
				//
				// }
				//
				// });
			}

		}

		@Override
		public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
			if (viewType == 1) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						EditMethodsActivity.this).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else if (viewType == 2) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						EditMethodsActivity.this).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						EditMethodsActivity.this).inflate(
						R.layout.item_methods_step_create_new, parent, false));
				return holder;
			}
		}
	}

	private void selectTypePopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_methods_step, null);

		TextView stepTv, solubilityCurveTv;

		stepTv = (TextView) conteView.findViewById(R.id.stepTv);
		solubilityCurveTv = (TextView) conteView
				.findViewById(R.id.solubilityCurveTv);

		final PopupWindow selectTypePopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		selectTypePopupWindow.setTouchable(true);

		selectTypePopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		selectTypePopupWindow.setBackgroundDrawable(new BitmapDrawable());
		selectTypePopupWindow.setTouchable(true);
		selectTypePopupWindow.setOutsideTouchable(true);
		selectTypePopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

		stepTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				newStepPopupWindow(view);
				selectTypePopupWindow.dismiss();
			}

		});
		solubilityCurveTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 先判断有几个溶解曲线
				for (int i = 0; i < activityMethodBeans.size(); i++) {
					if ("solubilityCurve".equals(activityMethodBeans.get(i)
							.getSteptType())) {
						// ByAlert.alert("最多只能添加一个溶解曲线");

						final AllShengDialog allShengDialog = new AllShengDialog(
								EditMethodsActivity.this, "", "最多只能添加一个溶解曲线",
								"确认");
						allShengDialog
								.setClicklistener(new ClickListenerInterface() {

									@Override
									public void OK() {

										allShengDialog.dismiss();
									}

									@Override
									public void Cancle() {
										// TODO Auto-generated method stub
										allShengDialog.dismiss();
									}
								});
						allShengDialog.show();
						return;
					}
				}
				newSolubilityCurvePopupWindow(view);
				selectTypePopupWindow.dismiss();
			}

		});

	}

	private void newStepPopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_step_edit, null);

		final TextView temperatureTv;
		final TextView goToTv, repititionsTv;
		final TextView hourTv, minuteTv, secondTv;
		TextView confirmTv;

		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);
		goToTv = (TextView) conteView.findViewById(R.id.goToTv);
		repititionsTv = (TextView) conteView.findViewById(R.id.repititionsTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);

		final PopupWindow newStepPopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});
		goToTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, goToTv, false, null, null);

			}
		});
		repititionsTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, repititionsTv, false, null,
						null);

			}
		});
		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_temcantnull));
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_hourcantnull));
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_minutecantnull));
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_secondcantnull));
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}

				}
				if (goToTv.getText().toString() != null
						&& !"".equals(goToTv.getText().toString())) {
					if (Integer.parseInt(goToTv.getText().toString()) >= activityMethodBeans
							.size() + 1) {
						ByAlert.alert(getString(R.string.editmethod_cantjump));
						return;
					}
					if (point3.get(Integer
							.parseInt(goToTv.getText().toString())) > 3) {
						ByAlert.alert(getString(R.string.editmethod_mostthree));
						return;
					}
				}

				HashSet<Integer> arryArrayLists = new HashSet<Integer>();
				for (int i = 0; i < activityMethodBeans.size(); i++) {
					arryArrayLists.add(i + 1);
				}

				for (ArrayList<Integer> ranges : range) {

					if (ranges.get(0) != null & ranges.get(1) != null) {
						int minNum, maxNum;
						minNum = ranges.get(0);
						maxNum = ranges.get(1);
						HashSet<Integer> delSet = new HashSet<Integer>();
						for (int j = minNum + 1; j < maxNum; j++) {
							// arryArrayLists.remove(j);
							delSet.add(j);

						}
						delSet.add(maxNum);
						arryArrayLists.removeAll(delSet);

						Boolean flag = false;
						for (int num : arryArrayLists) {

							if (goToTv.getText().toString() != null
									&& !"".equals(goToTv.getText().toString())) {
								if (Integer.parseInt(goToTv.getText()
										.toString()) == num) {
									flag = true;
								}
							} else {
								flag = true;
							}

						}
						if (!flag) {
							ByAlert.alert(getString(R.string.editmethod_cantthisjump));
							return;
						}

					} else {

					}

				}

				if (goToTv.getText().toString() != null
						&& !"".equals(goToTv.getText().toString())) {
					ArrayList<Integer> linShilist = new ArrayList<Integer>();
					linShilist.add(Integer
							.parseInt(goToTv.getText().toString()));
					linShilist.add(activityMethodBeans.size() + 1);

					point3.put(Integer.parseInt(goToTv.getText().toString()),
							point3.get(Integer.parseInt(goToTv.getText()
									.toString())) + 1);

					range.add(linShilist);
				}

				// ByAlert.alert("如果选中下一步，就必须要添加循环次数创建");

				activityMethodBeans.add(new MethodBean("step", temperatureTv
						.getText() + "", hourTv.getText() + ":"
						+ minuteTv.getText() + ":" + secondTv.getText(), goToTv
						.getText().toString(), repititionsTv.getText()
						.toString(), ""));

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointnumber++;
				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();
				totalTv.setText("总计" + recyclerViewAdapter.getItemCount() + "步");
				newStepPopupWindow.dismiss();
			}
		});

		newStepPopupWindow.setTouchable(true);

		newStepPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		newStepPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		newStepPopupWindow.setTouchable(true);
		newStepPopupWindow.setOutsideTouchable(true);
		newStepPopupWindow.showAtLocation(view, Gravity.CENTER, 154, 12);

	}

	private void newSolubilityCurvePopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_solubility_curve_edit, null);

		final TextView temperature1Tv, hour1Tv, minute1Tv, second1Tv;
		final TextView temperature2Tv, hour2Tv, minute2Tv, second2Tv;
		final TextView temperature3Tv, hour3Tv, minute3Tv, second3Tv;
		final TextView deltaTTv, cancelTv, confirmTv;

		temperature1Tv = (TextView) conteView.findViewById(R.id.temperature1Tv);
		temperature2Tv = (TextView) conteView.findViewById(R.id.temperature2Tv);
		temperature3Tv = (TextView) conteView.findViewById(R.id.temperature3Tv);
		hour1Tv = (TextView) conteView.findViewById(R.id.hour1Tv);
		minute1Tv = (TextView) conteView.findViewById(R.id.minute1Tv);
		second1Tv = (TextView) conteView.findViewById(R.id.second1Tv);
		hour2Tv = (TextView) conteView.findViewById(R.id.hour2Tv);
		minute2Tv = (TextView) conteView.findViewById(R.id.minute2Tv);
		second2Tv = (TextView) conteView.findViewById(R.id.second2Tv);
		hour3Tv = (TextView) conteView.findViewById(R.id.hour3Tv);
		minute3Tv = (TextView) conteView.findViewById(R.id.minute3Tv);
		second3Tv = (TextView) conteView.findViewById(R.id.second3Tv);

		deltaTTv = (TextView) conteView.findViewById(R.id.deltaTTv);

		cancelTv = (TextView) conteView.findViewById(R.id.cancelTv);
		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);

		final PopupWindow newSolubilityCurvePopupWindow = new PopupWindow(
				conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		temperature1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature1Tv, true, null,
						null);

			}
		});
		hour1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		hour2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		hour3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		minute1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		minute2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		minute3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		second1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		second2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		second3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		temperature2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature2Tv, true, null,
						null);

			}
		});

		temperature3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature3Tv, true, null,
						null);

			}
		});

		deltaTTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, deltaTTv, true, null, null);

			}
		});
		cancelTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				newSolubilityCurvePopupWindow.dismiss();
			}
		});
		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperature1Tv.getText().toString().trim())
						| "".equals(temperature2Tv.getText().toString().trim())
						| "".equals(temperature3Tv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_temcantnull));
					return;
				} else {
					if (Integer.parseInt(temperature1Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
					if (Integer.parseInt(temperature2Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
					if (Integer.parseInt(temperature3Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
				}
				if ("".equals(minute1Tv.getText().toString().trim())
						| "".equals(minute2Tv.getText().toString().trim())
						| "".equals(minute3Tv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_minutecantnull));
				} else {
					if (Integer.parseInt(minute1Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}
					if (Integer.parseInt(minute2Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}
					if (Integer.parseInt(minute3Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}
				}
				if ("".equals(second1Tv.getText().toString().trim())
						| "".equals(second2Tv.getText().toString().trim())
						| "".equals(second3Tv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_secondcantnull));
				} else {
					if (Integer.parseInt(second1Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}
					if (Integer.parseInt(second2Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}
					if (Integer.parseInt(second3Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}
				}
				if ("".equals(deltaTTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_deltatcantnull));
				} else {
					if (Float.parseFloat(deltaTTv.getText().toString().trim()) >= 100) {
						ByAlert.alert(getString(R.string.editmethod_deltatcant100));
						return;
					}
				}
				activityMethodBeans.add(new MethodBean("step", temperature1Tv
						.getText().toString() + "", hour1Tv.getText()
						.toString()
						+ ":"
						+ minute1Tv.getText().toString()
						+ ":" + second1Tv.getText().toString(), "", "", ""));
				activityMethodBeans.add(new MethodBean("step", temperature2Tv
						.getText().toString() + "", hour2Tv.getText()
						.toString()
						+ ":"
						+ minute2Tv.getText().toString()
						+ ":" + second2Tv.getText().toString(), "", "", ""));
				activityMethodBeans
						.add(new MethodBean("solubilityCurve", temperature3Tv
								.getText().toString() + "", hour3Tv.getText()
								.toString()
								+ ":"
								+ minute3Tv.getText().toString()
								+ ":"
								+ second3Tv.getText().toString(), "", "", ""
								+ deltaTTv.getText().toString()
										.replace("℃", "").replace("+", "") + ""));

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);

				pointnumber++;

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);

				pointnumber++;
				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointnumber++;

				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();
				totalTv.setText("总计" + recyclerViewAdapter.getItemCount() + "步");
				newSolubilityCurvePopupWindow.dismiss();

			}
		});

		newSolubilityCurvePopupWindow.setTouchable(true);

		newSolubilityCurvePopupWindow
				.setTouchInterceptor(new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {

						return false;
						// 这里如果返回true的话，touch事件将被拦截
						// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
					}

				});

		newSolubilityCurvePopupWindow
				.setBackgroundDrawable(new BitmapDrawable());
		newSolubilityCurvePopupWindow.setTouchable(true);
		newSolubilityCurvePopupWindow.setOutsideTouchable(true);
		newSolubilityCurvePopupWindow.showAtLocation(view, Gravity.CENTER, 145,
				12);

	}

	// 配置数字键盘的popupwindow
	private void numberKeyBoardPopupWindow(View v, final TextView textv,
			Boolean type, final TextView minuteTv, final TextView secondTv) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_numkeyboard_method, null);

		final EditText showTv;
		TextView num0Tv, num1Tv, num2Tv, num3Tv, num4Tv, num5Tv, num6Tv, num7Tv, num8Tv, num9Tv, num10Tv, cancelTv, confirmTv, delTv;
		showTv = (EditText) conteView.findViewById(R.id.showTv);
		num0Tv = (TextView) conteView.findViewById(R.id.num0Tv);
		num1Tv = (TextView) conteView.findViewById(R.id.num1Tv);
		num2Tv = (TextView) conteView.findViewById(R.id.num2Tv);
		num3Tv = (TextView) conteView.findViewById(R.id.num3Tv);
		num4Tv = (TextView) conteView.findViewById(R.id.num4Tv);
		num5Tv = (TextView) conteView.findViewById(R.id.num5Tv);
		num6Tv = (TextView) conteView.findViewById(R.id.num6Tv);
		num7Tv = (TextView) conteView.findViewById(R.id.num7Tv);
		num8Tv = (TextView) conteView.findViewById(R.id.num8Tv);
		num9Tv = (TextView) conteView.findViewById(R.id.num9Tv);
		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		cancelTv = (TextView) conteView.findViewById(R.id.cancelTv);
		delTv = (TextView) conteView.findViewById(R.id.delTv);

		final PopupWindow numberKeyBoardPopupWindow = new PopupWindow(
				conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (showTv.getText().length() == 0) {
					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {

						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

					} else if (R.id.secondTv == textv.getId()) {

						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}
					numberKeyBoardPopupWindow.dismiss();
					return;
				}
				if (R.id.hourTv == textv.getId()
						| R.id.minuteTv == textv.getId()
						| R.id.secondTv == textv.getId()) {

					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {
						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

						showTv.setText(result + "");
					} else if (R.id.secondTv == textv.getId()) {

						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}

					DecimalFormat df = new DecimalFormat("00");
					textv.setText(df.format(Integer.parseInt(showTv.getText()
							.toString())) + "");

					numberKeyBoardPopupWindow.dismiss();
				} else {
					textv.setText(showTv.getText());
					numberKeyBoardPopupWindow.dismiss();
				}

			}
		});

		if (type) {
			cancelTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					showTv.setText(showTv.getText().append("."));
					Selection.setSelection(showTv.getText(), showTv.getText()
							.length());

				}
			});
		} else {
			numberKeyBoardPopupWindow.dismiss();
		}

		delTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!TextUtils.isEmpty(showTv.getText().toString())) {
					showTv.setText(showTv
							.getText()
							.toString()
							.substring(0,
									showTv.getText().toString().length() - 1));
					Selection.setSelection(showTv.getText(), showTv.getText()
							.length());
				}

			}
		});
		num0Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("0"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("1"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("2"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num4Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("4"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num5Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("5"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num6Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("6"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num7Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("7"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num8Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("8"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num9Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("9"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		numberKeyBoardPopupWindow.setTouchable(true);

		numberKeyBoardPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				// if (R.id.hourTv == textv.getId()) {
				// minuteTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// textv.setBackground(getResources().getDrawable(
				// R.drawable.shape_darkblueblackframe));
				// } else if (R.id.minuteTv == textv.getId()) {
				//
				// minuteTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// secondTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_darkblueblackframe));
				//
				// } else if (R.id.secondTv == textv.getId()) {
				//
				// secondTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// }
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		numberKeyBoardPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		numberKeyBoardPopupWindow.setTouchable(true);
		numberKeyBoardPopupWindow.setOutsideTouchable(true);
		numberKeyBoardPopupWindow.showAtLocation(v, Gravity.CENTER, 392, 0);

	}

	private void upDate1PopupWindow(final View view, final int position,
			final TextView textview, final int indexStep) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_step_edit, null);

		final TextView temperatureTv, stepName;
		final TextView goToTv, repititionsTv;
		final TextView hourTv, minuteTv, secondTv;
		LinearLayout line;
		TextView confirmTv, repititiontextTv, delTv;
		TextView gototextTv;

		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);
		goToTv = (TextView) conteView.findViewById(R.id.goToTv);
		repititionsTv = (TextView) conteView.findViewById(R.id.repititionsTv);
		gototextTv = (TextView) conteView.findViewById(R.id.gototextTv);
		repititiontextTv = (TextView) conteView
				.findViewById(R.id.repititiontextTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		stepName = (TextView) conteView.findViewById(R.id.stepName);
		line = (LinearLayout) conteView.findViewById(R.id.line);
		delTv = (TextView) conteView.findViewById(R.id.delTv);
		line.setBackground(getResources().getDrawable(R.drawable.stepupdate));
		final PopupWindow upDate1PopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
		temperatureTv.setText(activityMethodBeans.get(position)
				.getTemperature().replace("℃", ""));
		goToTv.setText(activityMethodBeans.get(position).getGoTo());
		repititionsTv.setText(activityMethodBeans.get(position)
				.getRepititions());
		String time = activityMethodBeans.get(position).getTime();
		hourTv.setText(time.substring(0, time.indexOf(":")));
		int firstSymbol;
		firstSymbol = time.indexOf(":");
		minuteTv.setText(time.substring(firstSymbol + 1,
				time.indexOf(":", firstSymbol + 1)));
		int secondSymbol;
		secondSymbol = time.indexOf(":", firstSymbol + 1);
		secondTv.setText(time.substring(time.indexOf(":", secondSymbol) + 1));
		int index = position + 1;
		stepName.setText("step" + index);

		delTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				dialogDel(indexStep, position, upDate1PopupWindow);
				upDate1PopupWindow.dismiss();
			}
		});

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});

		if (position == 0) {
			goToTv.setVisibility(View.INVISIBLE);
			gototextTv.setVisibility(View.INVISIBLE);
			repititionsTv.setVisibility(View.INVISIBLE);
			repititiontextTv.setVisibility(View.INVISIBLE);

		}
		goToTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, goToTv, false, null, null);

			}
		});
		repititionsTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, repititionsTv, false, null,
						null);

			}
		});
		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				hourTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);

				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);
				// minuteTv.setBackground(getResources().getDrawable(R.drawable.shape_blackframe));
				// secondTv.setBackground(getResources().getDrawable(R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);
				// secondTv.setBackground(getResources().getDrawable(R.drawable.shape_blackframe));

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				minuteTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				secondTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_temcantnull));
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_hourcantnull));
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_minutecantnull));
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_secondcantnull));
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}

				}
				if (!"".equals(goToTv.getText().toString())
						|| goToTv.getText().toString() != null) {

					if (position != 0) {

						if (!TextUtils.isEmpty(goToTv.getText().toString())) {
							if (Integer.parseInt(goToTv.getText().toString()) >= activityMethodBeans
									.size() + 1) {
								ByAlert.alert(getString(R.string.editmethod_cantjump));
								return;
							}
						}

					}

				} else if ("0".equals(goToTv.getText().toString())) {
					ByAlert.alert(getString(R.string.editmethod_cantjump0));
				}

				if (position != 0) {

					if (!TextUtils.isEmpty(activityMethodBeans.get(position)
							.getGoTo())) {
						ArrayList<Integer> linshilist = new ArrayList<Integer>();
						linshilist.add(Integer.parseInt(activityMethodBeans
								.get(position).getGoTo()));
						linshilist.add(position);
						range.remove(linshilist);
					}

				}

				HashSet<Integer> arryArrayLists = new HashSet<Integer>();
				for (int i = 0; i < activityMethodBeans.size(); i++) {
					arryArrayLists.add(i + 1);
				}

				for (ArrayList<Integer> ranges : range) {

					if (ranges.get(0) != null & ranges.get(1) != null) {
						int minNum, maxNum;
						minNum = ranges.get(0);
						maxNum = ranges.get(1);
						HashSet<Integer> delSet = new HashSet<Integer>();
						for (int j = minNum + 1; j < maxNum; j++) {
							// arryArrayLists.remove(j);
							delSet.add(j);

						}
						arryArrayLists.removeAll(delSet);

						Boolean flag = false;
						for (int num : arryArrayLists) {
							if (!TextUtils.isEmpty(goToTv.getText().toString())) {
								if (Integer.parseInt(goToTv.getText()
										.toString()) == num) {
									flag = true;
								}
							} else {
								flag = true;
							}

						}
						if (!flag) {
							ByAlert.alert(getString(R.string.editmethod_cantthisjump));
//							ByAlert.alert("若无法达到需要的跳转，请删除步骤后重新设置！");
							return;
						}

					} else {

					}

				}

				if (position != 0) {
					if (!TextUtils.isEmpty(goToTv.getText().toString())) {
						ArrayList<Integer> linShilist = new ArrayList<Integer>();
						linShilist.add(Integer.parseInt(goToTv.getText()
								.toString()));
						linShilist.add(activityMethodBeans.size() + 1);

						range.add(linShilist);
					}

				}

//				ByAlert.alert("如果选中下一步，就必须要添加循环次数创建");
				activityMethodBeans.get(position).setTemperature(
						temperatureTv.getText() + "");
				activityMethodBeans.get(position).setTime(
						hourTv.getText() + ":" + minuteTv.getText() + ":"
								+ secondTv.getText());
				activityMethodBeans.get(position).setGoTo(
						goToTv.getText().toString());
				activityMethodBeans.get(position).setRepititions(
						repititionsTv.getText().toString());

				pointMap.remove(position * 2);
				pointMap.remove(position * 2 + 1);

				pointMap.put(
						position * 2,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				pointMap.put(
						position * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);

				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();

				view.setBackground(getResources().getDrawable(
						R.drawable.step_title_un));
				textview.setTextColor(getResources().getColor(R.color.black));
				totalTv.setText("总计" + recyclerViewAdapter.getItemCount() + "步");
				upDate1PopupWindow.dismiss();
			}
		});

		upDate1PopupWindow.setTouchable(true);

		upDate1PopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				view.setBackground(getResources().getDrawable(
						R.drawable.step_title_un));
				textview.setTextColor(getResources().getColor(R.color.black));
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss

			}

		});

		upDate1PopupWindow.setBackgroundDrawable(new BitmapDrawable());
		upDate1PopupWindow.setTouchable(true);
		upDate1PopupWindow.setOutsideTouchable(true);
		upDate1PopupWindow.showAtLocation(view, Gravity.CENTER, 154, 12);

	}

	private void upDate2PopupWindow(final View view, final int position,
			final TextView textview, final int indexStep) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_solubility_curve_newcreate, null);

		Button addBtn, minusBtn;
		final TextView temperatureTv, stepName;
		final TextView deltaTTv;
		final TextView hourTv, minuteTv, secondTv;
		TextView confirmTv, delTv;
		LinearLayout line;

		addBtn = (Button) conteView.findViewById(R.id.addBtn);
		minusBtn = (Button) conteView.findViewById(R.id.minusBtn);
		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		deltaTTv = (TextView) conteView.findViewById(R.id.deltaTTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		stepName = (TextView) conteView.findViewById(R.id.stepName);
		line = (LinearLayout) conteView.findViewById(R.id.line);
		delTv = (TextView) conteView.findViewById(R.id.delTv);

		line.setBackground(getResources().getDrawable(R.drawable.stepupdate));

		final PopupWindow upDate2PopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		int index = position + 1;
		stepName.setText("step" + index);
		temperatureTv.setText(activityMethodBeans.get(position)
				.getTemperature());

		String time = activityMethodBeans.get(position).getTime();
		hourTv.setText(time.substring(0, time.indexOf(":")));
		int firstSymbol;
		firstSymbol = time.indexOf(":");
		minuteTv.setText(time.substring(firstSymbol + 1,
				time.indexOf(":", firstSymbol + 1)));
		int secondSymbol;
		secondSymbol = time.indexOf(":", firstSymbol + 1);
		secondTv.setText(time.substring(time.indexOf(":", secondSymbol) + 1));
		deltaTTv.setText(activityMethodBeans.get(position).getDeltaT()
				.replace("℃", "").replace("+", ""));

		final DecimalFormat df = new DecimalFormat("###0.0");

		delTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogDel(indexStep, position, upDate2PopupWindow);

			}
		});

		addBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String result = df.format((Double.parseDouble(deltaTTv
						.getText().toString()) + (Double) 0.1));
				deltaTTv.setText(result);

			}
		});
		minusBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String result = df.format((Double.parseDouble(deltaTTv
						.getText().toString()) - (Double) 0.1));
				deltaTTv.setText(result);
			}
		});

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});

		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_temcantnull));
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert(getString(R.string.editmethod_temcant100));
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_hourcantnull));
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_minutecantnull));
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert(getString(R.string.editmethod_minutecant60));
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert(getString(R.string.editmethod_secondcantnull));
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert(getString(R.string.editmethod_secondcant60));
						return;
					}

				}

				activityMethodBeans.get(position).setTemperature(
						temperatureTv.getText() + "");
				activityMethodBeans.get(position).setTime(
						hourTv.getText() + ":" + minuteTv.getText() + ":"
								+ secondTv.getText());
				activityMethodBeans.get(position).setDeltaT(
						deltaTTv.getText().toString() + "");

				pointMap.remove(position * 2);
				pointMap.remove(position * 2 + 1);

				pointMap.put(
						position * 2,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				pointMap.put(
						position * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				recyclerViewAdapter.notifyDataSetChanged();
				upDate2PopupWindow.dismiss();
				UpdateView();
				view.setBackground(getResources().getDrawable(
						R.drawable.step_title_un));
				textview.setTextColor(getResources().getColor(R.color.black));
				totalTv.setText("总计" + recyclerViewAdapter.getItemCount() + "步");
			}
		});

		upDate2PopupWindow.setTouchable(true);

		upDate2PopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				view.setBackground(getResources().getDrawable(
						R.drawable.step_title_un));
				textview.setTextColor(getResources().getColor(R.color.black));
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		upDate2PopupWindow.setBackgroundDrawable(new BitmapDrawable());
		upDate2PopupWindow.setTouchable(true);
		upDate2PopupWindow.setOutsideTouchable(true);
		upDate2PopupWindow.showAtLocation(view, Gravity.CENTER, 154, 12);

	}

	// 初始化折线图
	private void initSimpleLineChart() {
		mSimpleLineChart = (SimpleLineChart) findViewById(R.id.simpleLineChart);

		// for (int i = 0; i < activityMethodBeans.size(); i++) {
		// pointMaps.get(i).put("temperature",
		// activityMethodBeans.get(i).getTemperature());
		// pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
		// pointMaps.get(i).put("deltaT",
		// activityMethodBeans.get(i).getDeltaT());
		// pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
		// pointMaps.get(i).put("repititions",
		// activityMethodBeans.get(i).getRepititions());
		//
		// }

		// if
		// ("SYBR".equals(SharedPreferencesUtils.get(EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		//
		// String[] xItem = { "Step1", "", "Step2", "", "Step3", "", "Step4",
		// "", "Step5", "", "Step6", "" };
		// String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
		// if (mSimpleLineChart == null)
		// Log.e("wing", "null!!!!");
		// mSimpleLineChart.setXItem(xItem);
		// mSimpleLineChart.setYItem(yItem);
		//
		// } else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))
		// | "taqman".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		// String[] xItem = { "Step1", "", "Step2", "", "Step3", "" };
		// String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
		// if (mSimpleLineChart == null)
		// Log.e("wing", "null!!!!");
		// mSimpleLineChart.setXItem(xItem);
		// mSimpleLineChart.setYItem(yItem);
		//
		// } else if ("其他".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))
		// | "Other".equals(SharedPreferencesUtils.get(
		// EditMethodsActivity.this,
		// BaseApplication.BASEINFORMATION_REAGENT, ""))) {
		// String[] xItem = { "" };
		// String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
		// if (mSimpleLineChart == null)
		// Log.e("wing", "null!!!!");
		// mSimpleLineChart.setXItem(xItem);
		// mSimpleLineChart.setYItem(yItem);
		// }

		// for (int i = 0; i < xItem.length; i++) {
		// pointMap.put(i, (int) (Math.random() * 5));
		// }

		for (int i = 0; i < 40; i++) {
			HashMap<String, Object> itemHashMap = new HashMap<String, Object>();
			// x
			itemHashMap.put("x", i);
			// y
			itemHashMap.put("y", "");
			// 温度
			itemHashMap.put("temperature", "");
			// 时间
			itemHashMap.put("time", "");
			// DeltaT
			itemHashMap.put("deltaT", "");
			// gotTo
			itemHashMap.put("goTo", "");
			// Repititions
			itemHashMap.put("repititions", "");
			pointMaps.add(itemHashMap);

		}
		for (int i = 0; i < activityMethodBeans.size(); i++) {
			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		if ("SYBR".equals(SharedPreferencesUtils.get(EditMethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))) {

			pointMap.put(0, 10 - 9);
			pointMap.put(1, 10 - 9);
			pointMap.put(2, 10 - 9);
			pointMap.put(3, 10 - 9);
			pointMap.put(4, 10 - 6);
			pointMap.put(5, 10 - 6);

			pointnumber = 3;

		} else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
				EditMethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))
				| "taqman".equals(SharedPreferencesUtils.get(
						EditMethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			pointMap.put(0, 10 - 9);
			pointMap.put(1, 10 - 9);
			pointMap.put(2, 10 - 9);
			pointMap.put(3, 10 - 9);
			pointMap.put(4, 10 - 6);
			pointMap.put(5, 10 - 6);
			pointnumber = 3;

		} else if ("其他".equals(SharedPreferencesUtils.get(
				EditMethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))
				| "Other".equals(SharedPreferencesUtils.get(
						EditMethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {

		}

		// pointMap.put(0, 10 - 3);
		// pointMap.put(1, 10 - 3);
		// pointMap.put(2, 10 - 1);
		// pointMap.put(3, 10 - 1);
		// pointMap.put(4, 10 - 0);
		// pointMap.put(5, 10 - 0);
		// pointMap.put(6, 10 - 0);
		// pointMap.put(7, 10 - 0);
		// pointMap.put(8, 10 - 0);
		// pointMap.put(9, 10 - 0);
		// pointMap.put(10, 10 - 0);
		// pointMap.put(11, 10 - 0);
		// pointMap.put(12, 10 - 0);
		// pointMap.put(13, 10 - 0);
		// pointMap.put(14, 10 - 0);
		// pointMap.put(15, 10 - 0);
		// pointMap.put(16, 10 - 0);
		// pointMap.put(17, 10 - 0);
		// pointMap.put(18, 10 - 0);
		// pointMap.put(19, 10 - 0);
		// pointMap.put(20, 10 - 0);
		// pointMap.put(21, 10 - 0);
		// pointMap.put(22, 10 - 0);
		// pointMap.put(23, 10 - 0);
		// pointMap.put(24, 10 - 0);
		// pointMap.put(25, 10 - 0);
		// pointMap.put(26, 10 - 0);
		// pointMap.put(27, 10 - 0);
		// pointMap.put(28, 10 - 0);
		// pointMap.put(29, 10 - 0);
		// pointMap.put(30, 10 - 0);
		// pointMap.put(31, 10 - 0);
		// pointMap.put(32, 10 - 0);
		// pointMap.put(33, 10 - 0);
		// pointMap.put(34, 10 - 0);
		// pointMap.put(35, 10 - 0);
		// pointMap.put(36, 10 - 0);
		// pointMap.put(37, 10 - 0);
		// pointMap.put(38, 10 - 0);
		// pointMap.put(39, 10 - 0);

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	private void UpdateView() {

		switch (pointMap.size()) {
		case 0:
			xItem = new String[] { "" };
			break;
		case 1:
			xItem = new String[] { "Step1" };
			break;
		case 2:
			xItem = new String[] { "Step1", "", };
			break;
		case 3:
			xItem = new String[] { "Step1", "", "Step2" };
			break;
		case 4:
			xItem = new String[] { "Step1", "", "Step2", "" };
			break;
		case 5:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3" };
			break;
		case 6:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "" };
			break;

		case 7:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4" };
			break;
		case 8:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "" };
			break;
		case 9:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5" };
			break;
		case 10:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "" };
			break;
		case 11:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6" };
			break;
		case 12:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "" };
			break;
		case 13:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7" };
			break;
		case 14:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "" };
			break;
		case 15:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "", "Step8" };
			break;
		case 16:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "" };
			break;
		case 17:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9" };
			break;
		case 18:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "" };
			break;
		case 19:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10" };
			break;
		case 20:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "" };
			break;
		case 21:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11" };
			break;
		case 22:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "" };
			break;
		case 23:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12" };
			break;
		case 24:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "" };
			break;
		case 25:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13" };
			break;
		case 26:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "" };
			break;
		case 27:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14" };
			break;
		case 28:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "" };
			break;
		case 29:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15" };
			break;
		case 30:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "" };
			break;
		case 31:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16" };
			break;
		case 32:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "" };
			break;
		case 33:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17" };
			break;
		case 34:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "" };
			break;
		case 35:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18" };
			break;
		case 36:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "" };
			break;
		case 37:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19" };
			break;
		case 38:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "" };
			break;
		case 39:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20" };
			break;
		case 40:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20", "" };

			break;

		default:
			break;
		}
		mSimpleLineChart.setXItem(xItem);

		for (int i = 0; i < activityMethodBeans.size(); i++) {
			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	// menu的弹出窗口
	private void showMethodsPopupWindow(final View view) {

		if (null == showMethodsPopupWindow
				|| !showMethodsPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(EditMethodsActivity.this)
					.inflate(R.layout.fragment_methods_menu, null);

			showMethodsPopupWindow = new PopupWindow(contentView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			showMethodsPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			showMethodsPopupWindow.setTouchable(true);
			showMethodsPopupWindow.setOutsideTouchable(true);
			showMethodsPopupWindow.showAsDropDown(view, -40, -335);

			showMethodsPopupWindow.setTouchInterceptor(new OnTouchListener() {

				@Override
				public boolean onTouch(View v, MotionEvent event) {

					if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
						showMethodsPopupWindow.dismiss();
						// btn.setSelected(!btn.isSelected());
						return true;
					}

					return false;
					// 这里如果返回true的话，touch事件将被拦截
					// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
				}

			});
			final TextView temperatureTv;
			final TextView volumeTv;
			final TextView stepSpinner, fourduTv;
			TextView confirmTv;
			final CheckBox checkBox;
			temperatureTv = (TextView) contentView
					.findViewById(R.id.temperatureTv);
			volumeTv = (TextView) contentView.findViewById(R.id.volumeTv);
			stepSpinner = (TextView) contentView.findViewById(R.id.stepSpinner);
			confirmTv = (TextView) contentView.findViewById(R.id.confirmTv);
			fourduTv = (TextView) contentView.findViewById(R.id.fourduTv);
			checkBox = (CheckBox) contentView.findViewById(R.id.checkBox);
			

			temperatureTv.setText(hotLidTemperature);
			volumeTv.setText(sampleVolumeString);
			stepSpinner.setText(readDataString);
			checkBox.setChecked(holdingCheckBox);
			fourduTv.setText(fourduString);
			checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					if (isChecked) {
						fourduTv.setEnabled(true);
					
					} else {
						fourduTv.setEnabled(false);
					
					}

				}
			});
			if (holdingCheckBox) {
				fourduTv.setEnabled(true);
			} else {
				fourduTv.setEnabled(false);
			}
			fourduTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					numberKeyBoardPopupWindow2(view, fourduTv, true, null, null);

				}
			});
			temperatureTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					numberKeyBoardPopupWindow2(view, temperatureTv, false,
							null, null);
				}
			});
			volumeTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					numberKeyBoardPopupWindow2(view, volumeTv, false, null,
							null);
				}
			});
			stepSpinner.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					numberKeyBoardPopupWindow2(view, stepSpinner, false, null,
							null);
				}
			});
			confirmTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (TextUtils.isEmpty(stepSpinner.getText().toString())) {
						ByAlert.alert(getString(R.string.editmethod_jumpcantnull));
						return;
					}
					if (TextUtils.isEmpty(temperatureTv.getText().toString())
							&& TextUtils.isEmpty(volumeTv.getText().toString())
							&& TextUtils.isEmpty(stepSpinner.getText()
									.toString())) {

						ByAlert.alert(getString(R.string.editmethod_cantnull));
						return;

					} else {
						try {
							if (Integer.parseInt(stepSpinner.getText()
									.toString().trim()) > activityMethodBeans.size()) {
								ByAlert.alert(getString(R.string.editmethod_readsteperror));
								return;
							}
						} catch (Exception e) {
//							ByAlert.alert("读取数据的步骤输入有误");

						}

					}

					hotLidTemperature = temperatureTv.getText().toString()
							.trim();
					sampleVolumeString = volumeTv.getText().toString().trim();
					readDataString = stepSpinner.getText().toString().trim();
					holdingCheckBox = checkBox.isChecked();
					fourduString = fourduTv.getText().toString();

					for (MethodBean bean : activityMethodBeans) {
						bean.setRightSelect(false);
					}

					activityMethodBeans.get(
							Integer.parseInt(readDataString) - 1)
							.setRightSelect(true);

					recyclerViewAdapter.notifyDataSetChanged();
					showMethodsPopupWindow.dismiss();
					// btn.setSelected(!btn.isSelected());
					cameraBoolean = true;
					ByAlert.alert(getString(R.string.editmethod_savesuccess));
				}
			});

		} else {
			// btn.setSelected(!btn.isSelected());
			showMethodsPopupWindow.dismiss();
		}

	}

	@Override
	public void onScrollChanged(MyHorizontalScrollView scrollView, int x,
			int y, int oldx, int oldy) {

		if (scrollView == downScrollView) {

			upScrollView.smoothScrollTo(x, 0);

		}
		if (scrollView == upScrollView) {
			downScrollView.smoothScrollTo(x, 0);

		}

	}

	private void dialogDel(final int index, final int position,
			final PopupWindow popupWindow) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this); // 先得到构造器
		builder.setTitle("提示"); // 设置标题
		builder.setMessage("是否确认删除?"); // 设置内容
		// builder.setIcon(R.mipmap.ic_launcher);// 设置图标，图片id即可
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { // 设置确定按钮
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// dialog.dismiss(); // 关闭dialog
						// Toast.makeText(MethodsActivity1.this, "确认" + which,
						// Toast.LENGTH_SHORT).show();
						if (index != activityMethodBeans.size()) {
							if ("solubilityCurve".equals(activityMethodBeans
									.get(position + 1).getSteptType())) {
								ByAlert.alert(getString(R.string.editmethod_cantdel));
								return;
							}

						}

						if (position != 0) {
							if (!TextUtils.isEmpty(activityMethodBeans.get(
									position).getGoTo())) {
								ArrayList<Integer> linshilist = new ArrayList<Integer>();
								linshilist.add(Integer
										.parseInt(activityMethodBeans.get(
												position).getGoTo()));
								linshilist.add(position);
								range.remove(linshilist);
							}

						}

						// methodBeans.remove(position);
						activityMethodBeans.remove(position);
						// notifyDataSetChanged();
						recyclerViewAdapter.notifyDataSetChanged();

						HashMap<Integer, Integer> pointMap1 = new HashMap();
						pointMap1.putAll(pointMap);
						// pointMap1.remove(position * 2);
						// pointMap1.remove(position * 2 + 1);
						pointMap.clear();
						int num = 0;
						for (int i = 0; i < pointMap1.size(); i++) {
							if (!(i == position * 2 || i == position * 2 + 1)) {
								pointMap.put(num, pointMap1.get(i));
								num++;
							}

						}
						UpdateView();

						pointnumber--;
						popupWindow.dismiss();

					}
				});
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { // 设置取消按钮
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						Toast.makeText(EditMethodsActivity.this, "取消" + which,
								Toast.LENGTH_SHORT).show();
					}
				});

		// builder.setNeutralButton("忽略", new DialogInterface.OnClickListener()
		// {// 设置忽略按钮
		// @Override
		// public void onClick(DialogInterface dialog, int which) {
		// dialog.dismiss();
		// Toast.makeText(MethodsActivity1.this, "忽略" + which,
		// Toast.LENGTH_SHORT).show();
		// }
		// });
		// 参数都设置完成了，创建并显示出来
		builder.create().show();
	}

	// 配置数字键盘的popupwindow
	private void numberKeyBoardPopupWindow2(View v, final TextView textv,
			Boolean type, final TextView minuteTv, final TextView secondTv) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_numkeyboard, null);

		final EditText showTv;
		TextView num0Tv, num1Tv, num2Tv, num3Tv, num4Tv, num5Tv, num6Tv, num7Tv, num8Tv, num9Tv, num10Tv, cancelTv, confirmTv;
		showTv = (EditText) conteView.findViewById(R.id.showTv);
		num0Tv = (TextView) conteView.findViewById(R.id.num0Tv);
		num1Tv = (TextView) conteView.findViewById(R.id.num1Tv);
		num2Tv = (TextView) conteView.findViewById(R.id.num2Tv);
		num3Tv = (TextView) conteView.findViewById(R.id.num3Tv);
		num4Tv = (TextView) conteView.findViewById(R.id.num4Tv);
		num5Tv = (TextView) conteView.findViewById(R.id.num5Tv);
		num6Tv = (TextView) conteView.findViewById(R.id.num6Tv);
		num7Tv = (TextView) conteView.findViewById(R.id.num7Tv);
		num8Tv = (TextView) conteView.findViewById(R.id.num8Tv);
		num9Tv = (TextView) conteView.findViewById(R.id.num9Tv);
		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		cancelTv = (TextView) conteView.findViewById(R.id.cancelTv);

		final PopupWindow numberKeyBoardPopupWindow = new PopupWindow(
				conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (showTv.getText().length() == 0) {
					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {

						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

					} else if (R.id.secondTv == textv.getId()) {

						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}
					numberKeyBoardPopupWindow.dismiss();
					return;
				}
				if (R.id.hourTv == textv.getId()
						| R.id.minuteTv == textv.getId()
						| R.id.secondTv == textv.getId()) {

					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {
						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

						showTv.setText(result + "");
					} else if (R.id.secondTv == textv.getId()) {

						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}

					DecimalFormat df = new DecimalFormat("00");
					textv.setText(df.format(Integer.parseInt(showTv.getText()
							.toString())) + "");

					numberKeyBoardPopupWindow.dismiss();
				} else {
					textv.setText(showTv.getText());
					numberKeyBoardPopupWindow.dismiss();
				}

			}
		});

		if (type) {
			cancelTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					showTv.setText(showTv.getText().append("."));
					Selection.setSelection(showTv.getText(), showTv.getText()
							.length());

				}
			});
		} else {
			numberKeyBoardPopupWindow.dismiss();
		}

		num0Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("0"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("1"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("2"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num4Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("4"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num5Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("5"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num6Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("6"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num7Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("7"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num8Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("8"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num9Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("9"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		numberKeyBoardPopupWindow.setTouchable(true);

		numberKeyBoardPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				// if (R.id.hourTv == textv.getId()) {
				// minuteTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// textv.setBackground(getResources().getDrawable(
				// R.drawable.shape_darkblueblackframe));
				// } else if (R.id.minuteTv == textv.getId()) {
				//
				// minuteTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// secondTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_darkblueblackframe));
				//
				// } else if (R.id.secondTv == textv.getId()) {
				//
				// secondTv.setBackground(getResources().getDrawable(
				// R.drawable.shape_blackframe));
				// }
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		numberKeyBoardPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		numberKeyBoardPopupWindow.setTouchable(true);
		numberKeyBoardPopupWindow.setOutsideTouchable(true);
		numberKeyBoardPopupWindow.showAtLocation(v, Gravity.CENTER, 110, 75);

	}
}
